/*
 * File User.java 
 */
package cs.entity;

import java.net.InetAddress;

/**
 * Represents a chat user (by username and ip address. <p>
 * Package  cs.entity
 * Project ChatSystemG1 - INSA 4INFOA1 - 2013/2014
 * @author Julie DUMONS & Juste OUEDRAOGO
 */
public class User {
	
	/**
	 * the user name
	 */
	private String username ; 
	
	/**
	 * the user ip address
	 */
	private InetAddress ipAddress ;
	
	/**
	 * constructor using the user name
	 */
	public User() {
		super(); 
	}
	
	/**
	 * constructor with 2 parameters
	 * @param username the user name
	 * @param addr the user ip address
	 */
	public User(String username, InetAddress addr) {
		super();
		this.username = username;
		this.ipAddress = addr;
	}
	
	/**
	 * get the user name
	 * @return the user name  
	 */
	public String getUsername() {
		return username;
	}
	
	/**
	 * sets the user name
	 * @param username
	 */
	public void setUsername(String username) {
		this.username = username;
	}
	
	/**
	 * gets the ip address
	 * @return
	 */
	public InetAddress getIpAddress() {
		return ipAddress;
	}
	
	/**
	 * sets the ip address
	 * @param adresseIP
	 */
	public void setIpAddress(InetAddress adresseIP) {
		this.ipAddress = adresseIP;
	}

	@Override
	public String toString() {
		return ""+username + " (" + ipAddress + ")";
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((ipAddress == null) ? 0 : ipAddress.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (ipAddress == null) {
			if (other.ipAddress != null)
				return false;
		} else if (!ipAddress.equals(other.ipAddress))
			return false;
		return true;
	} 
	
	
	
	
}
